using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace TimeWar
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary> 
    public class PlayDemoScreen : Screen
    {
        protected Dalek dalek = null;
        protected Game gameObj = null;
        protected Starship enterprise_E = null;
        protected Starship XWingFighter = null;
        protected Starship MilleniumFalcon = null;
        protected Starship Tardis = null;

        public PlayDemoScreen(Game game)
            : base(game)
        {

            // TODO: Construct any child components here
            gameObj = game;
            dalek = new Dalek(game, this);
            enterprise_E = new Starship(game, "Content\\Models\\StarTrek\\Federation\\Starships\\SovereignBc", this);
            //XWingFighter = new Starship(game, "Content\\Models\\XWing");
            //MilleniumFalcon = new Starship(game, "Content\\Models\\MilleniumFalcon");
            //dalek.ModelLocation = "Content\\Models\\DrWho\\Dalek\\Characters\\Dalek";

            dalek.Position = new Vector3(10f, 0f, 100f);
            dalek.Scale = 0.05f;
            dalek.Chased = false;
            dalek.Player = PlayerIndex.Two;
            dalek.Mass = 100;

            enterprise_E.Position = new Vector3(10f, 0, 0);
            

            //enterprise_E.CameraPosition = gameCamera.CameraPosition;
            enterprise_E.Scale = 0.025f;

            //enterprise_E.Velocity = new Vector3(1.0f, 1.0f, 1.0f);

            enterprise_E.Update(game.TargetElapsedTime, game.TargetElapsedTime);
            enterprise_E.Chased = true;
            enterprise_E.Player = PlayerIndex.One;
            enterprise_E.ObjectType = ObjectTypes.Playable;

            addScreenObject(dalek);
            addScreenObject(enterprise_E);

            setupCameras();

        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// 
        public override GameState Update(TimeSpan time, TimeSpan elapsedTime)
        {
            GameState currState = base.Update(time, elapsedTime);

            XInputHelper.GamePads[PlayerIndex.One].Update(game, Keyboard.GetState());

            if (XInputHelper.GamePads[PlayerIndex.One].State.IsButtonDown(Buttons.Back))
            {
                game.Exit();
            }

            return currState;

        }

        public override void Render()
        {
            IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)GameInstance.Services.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice device = graphicsService.GraphicsDevice;

            //Sprites will always be at the back.
            device.RenderState.DepthBufferWriteEnable = false;
            device.Clear(Color.Black);

            chaseCamera.Update(TimeSpan.Zero);

            //SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);
            base.Render();
        }

    }
}